from db.db_help import DBHelp
from model.base_model import *
from flask import request, render_template

from utils.jwt_util import genToken


class AccountServer:
    @classmethod
    def login1(cls):
        error = None
        return render_template('index.html', error=error)

    @classmethod
    def login(cls):
        if request.form.get('username') is None or request.form.get('password') is None:
            return MyBaseModel(code=500, msg="用户名或密码不能为空")
        else:
            rows = DBHelp.selectRows("select * from user WHERE userName = %s and passWord = %s",
                                     [request.form['username'], request.form['password']])
            if len(rows) > 0:
                rows[0]['token'] = genToken(rows[0]['uid'])
                return MyBaseModel(code=200, msg="登录成功", data=rows[0])
            else:
                return MyBaseModel(code=500, msg="用户名或密码输入有误", data=None)

    @classmethod
    async def outLogin(cls):
        if 1 == 1:
            return True
